const router = require('koa-router')()
const Index = require("../app/home/index")
const MEMBER = require("../app/home/member.js")
const MAPS = require("../app/home/map.js")
const multer = require('koa-multer');
router.prefix('/api')
router.get('/getLocation', MAPS.getLocation)

router.get('/getMenu',Index.getMenu)
router.get('/getAdList',Index.getAdList)
router.get('/getGoodsList',Index.getGoodsList)
router.get('/getGoodsDetail',Index.getGoodsDetail)
router.get('/searchGoods',Index.searchGoods)

router.get('/getYzm',MEMBER.getYzm)
router.post("/telLogin",MEMBER.telLogin)
//配置    
var storage = multer.diskStorage({
	//文件保存路径
	destination: function(req, file, cb) {
		cb(null, 'public/uploads/') //注意路径必须存在
	},
	//修改文件名称
	filename: function(req, file, cb) {
		var fileFormat = (file.originalname).split(".");
		cb(null, Date.now() + "." + fileFormat[fileFormat.length - 1]);
	}
})
//加载配置
var upload = multer({
	storage: storage
})

router.post('/upload', upload.single('file'), async (ctx, next) => {
	ctx.body = {
		code: 0,
		codeInfo: "成功",
		data: {
			filename: '/uploads/' + ctx.req.file.filename, //返回文件名
		}
	}
});
module.exports = router
